package listbyorder.access001_100.test3;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/6 12:58
 */
public class Solution1 {

    // 双指针窗口————利用数组存储历史信息
    public int lengthOfLongestSubstring(String s) {
        int ans = 0;
        int[] index = new int[128];
        int l = 0, r = 0;
        while (r < s.length()) {
            char cur = s.charAt(r);
            if (index[cur] == 0) {
                r++;
                index[cur]++;
            } else {
                ans = Math.max(ans, r - l);
                index[s.charAt(l++)]--;
            }
        }
        ans = Math.max(ans, r - l);
        return ans;
    }
}
